<template>
  <div class="comp_home-showcase-item-wrap">
    <!-- type=2 -->
    <template v-if="info.type == 2">
      <div class="title-wrap1" @click="jumpUrl(info.href)">
        <img class="bgImg" :src="info.bgImg" alt="">
        <div class="title">
          {{ info.title }}
          <img class="arrow-white" src="../../assets/images/indexNew/whiteArrow.png" alt="">
        </div>
        <div class="text">{{ info.label }}</div>
      </div>
      <div class="product-wrap1">
        <div class="item" v-for="(item, index) in info.products" :key="index">
          <v-product-item :info="item" :key="index"></v-product-item>
        </div>
      </div>
    </template>
    <template v-if="info.type == 3">
      <div class="title-wrap2 df-c" @click="jumpUrl(info.href)">
        <img class="bgImg" :src="info.bgImg" alt="">
        <div class="title">{{ info.title }}</div>
        <img class="arrow-grey" src="../../assets/images/indexNew/greyArrow.png" alt="">
        <div class="text-btn df-c" :style="{ backgroundColor: info.labelColor }">{{ info.label }}</div>
      </div>
      <div class="product-wrap2">
        <h-product-item v-for="(item, index) in info.products" :info="item" :key="index"></h-product-item>
      </div>
    </template>
  </div>
</template>

<script scoped type="text/babel">
import HProductItem from "./HProductItem"
import VProductItem from "./VProductItem"
import { mapGetters, mapActions } from 'vuex'

export default {
  name: "ShowCaseItem",
  components: {
    HProductItem,
    VProductItem
  },
  props: {
    info: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
    }
  },
  computed: {
  },
  watch: {},
  methods: {
    ...mapActions(['openRouteByWebview']),
    jumpUrl(href) {
      if (!href) {
        return
      }
      if (href.indexOf(this.$env.backUrlBase) > -1) {
        href = href.split('#')[1];
      }
      this.openRouteByWebview({
        route: this.encodeChineseInUrl(href),
        jumpType: 'push',
        sendLocation: true
      })
      return;
    },
    encodeChineseInUrl(url) {
      return url.replace(/([?&]pageName=)([^&]+)/g, function (match, p1, p2) {
        // p1是"pageName="，p2是参数值
        return p1 + encodeURIComponent(p2);
      });
    },
  },
  mounted() {
  },
}
</script>

<style scoped lang="scss" rel="stylesheet/scss">
.comp_home-showcase-item-wrap {
  width: 100%;
  text-align: center;
  box-sizing: border-box;
  background-color: #fff;

  .title-wrap1 {
    padding: 8px 10px 28px;
    background: linear-gradient(180deg, #DCF0FB 0%, #C1E7FB 100%);
    text-align: left;
    position: relative;

    .bgImg {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
    }

    .title {
      font-weight: 700;
      font-size: 18px;
      color: #333333;
      line-height: 24px;
      position: relative;
      z-index: 3;
    }

    .arrow-white {
      width: 13px;
      height: 13px;
      margin-left: 10px;
      position: relative;
      z-index: 3;
    }

    .text {
      font-size: 12px;
      color: #666666;
      line-height: 16px;
      position: relative;
      z-index: 3;
    }
  }

  .product-wrap1 {
    padding: 12px;
    background-color: #fff;
    border-radius: 12px;
    margin-top: -20px;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    position: relative;
    z-index: 3;

    .item {
      margin-right: 8px;
      margin-bottom: 8px;

      &:nth-child(2n) {
        margin-right: 0;
      }
    }
  }

  // 第二种样式
  .title-wrap2 {
    padding: 8px 10px 28px;
    // background: linear-gradient(180deg, #DCF0FB 0%, #C1E7FB 100%);
    position: relative;
    .title {
      font-weight: 700;
      font-size: 18px;
      color: #333333;
      position: relative;
      z-index: 3;
    }

    .bgImg {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
    }

    .arrow-grey {
      width: 13px;
      height: 13px;
      margin-left: 2px;
      position: relative;
      z-index: 3;
    }

    .text-btn {
      padding: 2px;
      font-family: MILanPro_DEMIBOLD--GB1, MILanPro_DEMIBOLD--GB1;
      font-weight: normal;
      font-size: 12px;
      color: #FFFFFF;
      // background: linear-gradient(112deg, #73DEB0 0%, #27BE7D 100%);
      border-radius: 6px;
      margin-left: 10px;
      // margin-top: 4px;
      position: relative;
      z-index: 3;
    }
  }

  .product-wrap2 {
    padding: 12px;
    background-color: #fff;
    margin-top: -20px;
    border-radius: 12px;
    position: relative;
    z-index: 3;
  }
}
</style>
